package com.spotmanger.project.modular.spottable.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spotmanger.project.common.core.utils.DataResult;
import com.spotmanger.project.modular.spottable.entity.SpottableProductivemineNewEntity;
import com.spotmanger.project.modular.spottable.service.SpottableProductivemineNewService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 生产矿山和废弃矿山图斑的信息表，所有生产矿山和废弃矿山图斑录入均需要填写该表。
 *
 * @author leihao
 * @email 1321451088@qq.com
 * @date 2021-09-20 10:53:23
 */
@Controller
@RequestMapping("/")
public class SpottableProductivemineNewController {

    @Autowired
    private SpottableProductivemineNewService spottableProductivemineNewService;


    /**
    * 跳转到页面
    */
    @GetMapping("/index/productivemineNew")
    public String productivemineNew() {
        return "spottable/spottableproductiveminenew/list";
        }


    @ApiOperation(value = "新增")
    @PostMapping("productivemineNew/add")
    @RequiresPermissions("productivemineNew:add")
    @ResponseBody
    public DataResult add(@RequestBody SpottableProductivemineNewEntity spottableProductivemine){
        spottableProductivemineNewService.save(spottableProductivemine);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("productivemineNew/delete")
    @RequiresPermissions("productivemineNew:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> TBBHs){
        spottableProductivemineNewService.removeByIds(TBBHs);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("productivemineNew/update")
    @RequiresPermissions("productivemineNew:update")
    @ResponseBody
    public DataResult update(@RequestBody SpottableProductivemineNewEntity spottableProductivemine){
        spottableProductivemineNewService.updateById(spottableProductivemine);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("productivemineNew/listByPage")
    @RequiresPermissions("productivemineNew:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody SpottableProductivemineNewEntity spottableProductivemine){
        Page page = new Page(spottableProductivemine.getPage(), spottableProductivemine.getLimit());
        LambdaQueryWrapper<SpottableProductivemineNewEntity> queryWrapper = spottableProductivemineNewService.searchByTBBH(spottableProductivemine);
        IPage<SpottableProductivemineNewEntity> iPage = spottableProductivemineNewService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }
}
